<%--
  Created by IntelliJ IDEA.
  User: teacher
  Date: 2023/7/14
  Time: 10:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>关键字搜索</title>
    <style>
        li{
            list-style: none;
            font-size: 14px;
        }
        #d1{
            border: 1px solid #5160fb;
            width: 300px;
            border-top: 0px;
            padding: 3px 5px;
            display: none;
        }
    </style>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.4.1.min.js"></script>
    <script>
        $(function(){
           $("#spell").keyup(function(){
               $("#d1").empty();
               if($(this).val() == ""){
                   $("#d1").hide();
                   return;
               }
               $.ajax({
                   type:"post",
                   <%--url:"${pageContext.request.contextPath}/query",--%>
                   url:"http://localhost:8080/ajax/query",
                   data:{"spell":$(this).val()},
                   dataType:"json",
                   success(datas){
                       if(datas.length == 0){
                           $("#d1").hide();
                           return;
                       }
                       $("#d1").show();
                       $(datas).each(function(){
                         $("#d1").append("<li>"+this.message+"</li>");
                       })
                   }
               })
           });
        });
    </script>
</head>
<body>
<input type="text" style="width: 312px;" id="spell">
<div id="d1">
    <%--<li>aaa</li>--%>
    <%--<li>bbb</li>--%>
    <%--<li>ccc</li>--%>
</div>
</body>
</html>
